#ifndef __SCOPELIST_H_
#define __SCOPELIST_H_

#include <QtCore/QSet>
#include <QtCore/QFileInfo>
#include <QtGui/QTreeView>

#include "proeditormodel.h"

namespace Qt4ProjectManager
{
    namespace Internal
	{
        class ProScopeFilter;
        class ProEditorModel;
    }
}

class ScopeList : public QTreeView
{
    Q_OBJECT
    Q_CLASSINFO("ClassID", "{5b68525e-103d-4a6f-9550-a8d050f18f81}")
    Q_CLASSINFO("InterfaceID", "{e938a5b7-1b4a-4e63-859d-ec07b383860b}")
    Q_CLASSINFO("EventsID", "{8f5e587c-a0c9-4660-b730-d8c895e1b3d4}")
    Q_CLASSINFO("ToSuperClass", "ScopeList")

public:
    ScopeList(QWidget *parent = 0);
    ~ScopeList();

public Q_SLOTS:
    void showModel(const QString &proFileName, const QString &contents, bool enabled);	// 显示模型和选择变量
    void selectFirstVariable();	// 在当前模型中选择第一个变量
    bool search(const QString &proFileName, const QString &contents);	// 在当前模型中搜索文件（在addFile之前添加的文件）
    bool isChanged(const QString &proFileName);
    QString removeFiles(const QString &proFileName);
    QString addFiles(const QString &proFileName);
    void addFile(const QString &file, const QString &var);

private:
    static QMap<QString, Qt4ProjectManager::Internal::ProEditorModel *> &modelMap();
    static QMap<Qt4ProjectManager::Internal::ProEditorModel *, int> &modelRefCount();

    static Qt4ProjectManager::Internal::ProEditorModel *aquireModel(const QString &fileName, const QString &contents);
    static void releaseModel(Qt4ProjectManager::Internal::ProEditorModel *editorModel);

    Qt4ProjectManager::Internal::ProScopeFilter *filter(Qt4ProjectManager::Internal::ProEditorModel *model);
    void ensureVariable(const QString &variable, Qt4ProjectManager::Internal::ProEditorModel *model);
    Qt4ProjectManager::Internal::ProEditorModel *proEditorModel(const QString &fileName, const QString &contents);

    QMap<Qt4ProjectManager::Internal::ProEditorModel *, Qt4ProjectManager::Internal::ProScopeFilter *> m_models;
    QMap<QString, Qt4ProjectManager::Internal::ProEditorModel *> m_proFileNameToModel;

    QMultiMap<QString, QFileInfo> m_files;
    QStringList m_filenames;
};
    
#endif //__SCOPELIST_H_
